#ifndef CMEMORY_H
#define CMEMORY_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

class CMemory {
public:
	~CMemory() {};
	void* allocMemory(int nMemCnt, bool bMemset);
	void freeMemory(void* pointer);

	static CMemory* getInstance() {
		if (NULL == m_pInstance)
		{
			//锁
			if (NULL == m_pInstance)
			{
				m_pInstance = new CMemory();	//第一次调用应该放在主线程中
				static CGarbageCollector clGarColl;
			}
		}
		return m_pInstance;
	}

	class CGarbageCollector {
	public:
		~CGarbageCollector() {
			if (CMemory::m_pInstance)
			{
				delete CMemory::m_pInstance;
				CMemory::m_pInstance = NULL;
			}
		}
	};

private:
	CMemory() {};
	static CMemory* m_pInstance;
};

#endif